<?php

/**
 * Maikuro CMS
 *
 * LICENSE:
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * The license is bundled with this package in the file LICENSE.txt.
 * You may also obtain a copy of the License at this URL:
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * @copyright  Copyright (c) 2010, Jonathan Hedrén
 * @author     Jonathan Hedrén <jonathan.hedren@gmail.com>
 * @license    http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
 */

?>

<h1><?php echo $title; ?></h1>
<form action="" method="post" id="page-form">
    <div id="page-content" class="container">

<?php if ($model->page->id): ?>
<a id="view-page" href="<?php echo $siteUrl . $model->page->permalink; ?>"><?php echo Translator::translate('View page'); ?></a>
<?php endif; ?>

        <fieldset>
            <legend><?php echo Translator::translate('Content'); ?></legend>
            <?php HtmlBinder::hiddenFor($model->page, 'id'); ?>
            <?php HtmlBinder::hiddenFor($model->page, 'rewriteId'); ?>
            <div class="field text">
                <?php
                    HtmlBinder::labelFor($model->page, 'title');
                    HtmlBinder::textBoxFor($model->page, 'title');
                    HtmlBinder::validationMessagesFor($model->page, 'title');
                ?>
            </div>
            <div class="field textarea">
                <?php
                    HtmlBinder::labelFor($model->page, 'content');
                    HtmlBinder::textareaFor($model->page, 'content');
                    HtmlBinder::validationMessagesFor($model->page, 'content');
                ?>
            </div>
        </fieldset>
    </div>

    <?php $this->renderSnippet('customFieldsFormPart', array('customFields' => $model->page->customFields)); ?>
    
    <div id="page-properties" class="container">
        <fieldset>
            <legend><?php echo Translator::translate('Properties'); ?></legend>

            <?php if ($model->page->id): ?>
                <p id="page-permalink"><?php echo Translator::translate('Permanent link') . ': ' . $model->page->permalink; ?></p>
            <?php endif; ?>

            <div class="field text date">
                <?php
                    HtmlBinder::labelFor($model->page, 'created');
                    HtmlBinder::textBoxFor($model->page, 'created');
                    HtmlBinder::validationMessagesFor($model->page, 'created');
                ?>
            </div>
            
            <div class="field text date">
                <?php
                    HtmlBinder::labelFor($model->page, 'updated');
                    HtmlBinder::textBoxFor($model->page, 'updated');
                    HtmlBinder::validationMessagesFor($model->page, 'updated');
                ?>
            </div>

            <div class="field text">
                <?php
                    HtmlBinder::labelFor($model->page, 'urlTitle');
                    HtmlBinder::textBoxFor($model->page, 'urlTitle');
                    HtmlBinder::validationMessagesFor($model->page, 'urlTitle');
                ?>
            </div>

            <div class="field select">
                <?php
                    HtmlBinder::labelFor($model->page, 'status');
                    HtmlBinder::selectFor($model->page, 'status', $model->statuses);
                    HtmlBinder::validationMessagesFor($model->page, 'status');
                ?>
            </div>

            <div class="field select">
                <?php
                    HtmlBinder::labelFor($model->page, 'parentId');
                    HtmlBinder::selectFor($model->page, 'parentId', $model->possibleParents);
                    HtmlBinder::validationMessagesFor($model->page, 'parentId');
                ?>
            </div>

            <div class="field select">
                <?php
                    $weights = array();
                    $i = -20;
                    while ($i <= 20) {
                        $weights[$i] = $i;
                        $i++;
                    }

                    HtmlBinder::labelFor($model->page, 'weight');
                    HtmlBinder::selectFor($model->page, 'weight', $weights);
                    HtmlBinder::validationMessagesFor($model->page, 'weight');
                ?>
            </div>

            <div class="field select">
                <?php
                    HtmlBinder::labelFor($model->page, 'template');
                    HtmlBinder::selectFor($model->page, 'template', $model->templates);
                    HtmlBinder::validationMessagesFor($model->page, 'template');
                ?>
            </div>
            <div class="field select">
                <?php
                    HtmlBinder::labelFor($model->page, 'childrenSortOrder');
                    HtmlBinder::selectFor($model->page, 'childrenSortOrder', $model->sortOrders);
                    HtmlBinder::validationMessagesFor($model->page, 'childrenSortOrder');
                ?>
            </div>
        </fieldset>
    </div>
    <div class="container actions">
        <input type="submit" class="neutral-action" name="cancel" value="<?php echo Translator::translate('Cancel'); ?>" />
        <input type="submit" class="positive-action" name="save" value="<?php echo Translator::translate('Save'); ?>" />
    </div>
</form>
